﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lp_Appointment.aspx.cs"
    Inherits="ZLDC.Estate.Quantify.lp_Appointment" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>预约工作安排</title>

    <script src="flexigrid/jquery.js" type="text/javascript"></script>

    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <link href="css/page.css" rel="stylesheet" type="text/css" />

    <script src="../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

    <script src="popup/popup2/popup.js" type="text/javascript"></script>

    <script type="text/javascript">
        function bindGrid() {

            $("#table1").flexigrid(
			{
			    sortname: "",
			    sortorder: "asc",
			    sortable: false,
			    usepager: false,
			    title: false,
			    rocmsg: '正在查询，请稍等...', //正在处理的提示信息
			    nomsg: '没有记录',
			    showTableToggleBtn: false,
			    width: "auto",
			    height: "500"
			}
		    );
            setColor();
        }
        function alifrm(uid, name, t_id, Rrow) {
            var day = document.getElementById('txtTime').value;
            //var endday = document.getElementById('txtendtime').value;
            ShowIframe("lp_Configuration_below.aspx?Rrow=" + Rrow + "&endday=" + escape(day) + "&daytime=" + escape(day) + "&type=2&t_id=" + t_id + "&user_id=" + uid, 700, 500, name + "预约工作分配");
        }

        function setColor() {
            var ta = document.getElementById('table1');
            for (var i = 1; i < ta.rows.length; i++) {
                var cell = ta.rows[i].cells[1].childNodes[0].type;

                if (cell == undefined) {
                    ta.rows[i].style.backgroundColor = 'red';

                }
            }
        }


        function chk(obj, on1, on2, on3) {
            var rowIndex = obj.parentNode.parentNode.rowIndex;
            if (obj.checked) {
                document.getElementById('table1').rows[rowIndex].cells[on1].childNodes[0].disabled = "disabled";
                //document.getElementById('table1').rows[rowIndex].cells[on2].childNodes[0].disabled = "disabled";
                document.getElementById('table1').rows[rowIndex].cells[on3].childNodes[0].disabled = "disabled";
            } else {
                document.getElementById('table1').rows[rowIndex].cells[on1].childNodes[0].disabled = "";
                //document.getElementById('table1').rows[rowIndex].cells[on2].childNodes[0].disabled = "";
                document.getElementById('table1').rows[rowIndex].cells[on3].childNodes[0].disabled = "";
            }
        }

        function popoList(type, userid, Rrow) {

            for (var i = 0; i < 4; i++) {

                document.getElementById('table1').rows[Rrow].cells[i].childNodes[0].onclick = "";
                document.getElementById('table1').rows[Rrow].cells[i].childNodes[0].disabled = "disabled";
            }

            document.getElementById('table1').rows[Rrow].cells[0].childNodes[6].value = "1";

        }
     
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Panel ID="Panel2" runat="server" Width="95%">
            日期:<asp:TextBox ID="txtTime" runat="server" onfocus="WdatePicker({minDate:'%y-%M-{%d+1}'})"></asp:TextBox>
            <%-- ~<asp:TextBox
                ID="txtendtime" runat="server" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'txtTime\')}'})"></asp:TextBox>&nbsp;--%>
            <asp:Button ID="btnExistsTime" runat="server" Text="我来安排" CssClass="button1" OnClick="btnExistsTime_Click"
                OnClientClick="return isTimeNotNul()" /><a id="aexists" style="color: Red" runat="server"></a>
            <table id="table1" border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' width="650px">
                <thead>
                    <tr>
                        <th align="center" width="60" bgcolor='d3eaef' class='STYLE6'>
                            姓名
                        </th>
                        <th align="center" width="80" bgcolor='d3eaef' class='STYLE6'>
                            自己选择
                        </th>
                        <th align="center" width="60" bgcolor='d3eaef' class='STYLE6'>
                            是否请假
                        </th>
                        <th align="center" width="180" bgcolor='d3eaef' class='STYLE6'>
                            工作建议
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="RpList" runat="server">
                        <ItemTemplate>
                            <tr>
                                <td class='STYLE10'>
                                    <a style="cursor: pointer" title="点击此处查看详细" onclick='alifrm("<%# Eval("Id")%>","<%# Eval("user_name")%>",<%# Eval("t_id") %>,<%# Container.ItemIndex + 1%>)'>
                                        <%# Eval("user_name")%></a>
                                    <asp:HiddenField ID="hidid" runat="server" Value='<%# Eval("id") %>' />
                                    <asp:HiddenField ID="hiddeptid" runat="server" Value='<%# Eval("t_id") %>' />
                                    <asp:HiddenField ID="hidSoure" runat="server" />
                                    <asp:HiddenField ID="hidname" runat="server" Value='<%# Eval("user_name") %>' />
                                    <asp:HiddenField ID="hidtf" runat="server"  />
                                </td>
                                <td class='STYLE10'>
                                    <asp:CheckBox ID="CheckBox2" runat="server" onclick="chk(this,2,3,0)" />
                                </td>
                                <td class='STYLE10'>
                                    <asp:CheckBox ID="CheckBox1" runat="server" onclick="chk(this,1,3,0)" />
                                </td>
                                <td class='STYLE10'>
                                    <asp:TextBox ID="txtRemark" Width="97%" Height="30px" TextMode="MultiLine" runat="server"></asp:TextBox>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
            <asp:Button ID="Button1" runat="server" Text="预约部署完成" CssClass="button1" OnClientClick="return addTime()"
                OnClick="Button1_Click" />

            <script type="text/javascript">

                function addTime() {
                    var TM = document.getElementById('txtTime').value;
                    // var endday = document.getElementById('txtendtime').value;
                    if (TM == '') {
                        alert('请选择工作时间！');
                        return false;
                    }
                    // if (!confirm('是否安排' + TM + '~' + endday + '日期工作?')) {
                    if (!confirm('是否安排' + TM + '日期工作?')) {
                        return false;
                    }
                    return true;
                }
            </script>

        </asp:Panel>

        <script type="text/javascript">
            window.onload = function ajaxList() {
                $.ajax({
                    type: "POST",
                    url: "AjaxServer.aspx",
                    dataType: 'json',
                    data: "alt=Reservation",
                    processData: false,
                    timeout: '10000',
                    success: function(msg) {

                        divlist(msg);

                    },
                    error: function() {
                        document.getElementById('divlist').innerHTML = "系统繁忙";
                    }

                });
            }
            function divlist(msg) {
                var arr = [];
                arr.push("<table width='500px' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
                arr.push("<tr bgcolor=\"#353c44\" >");
                arr.push("<td width=\"80px\"  style='text-align: center;background-color: #d3eaef'  >");
                arr.push("<div >预约日期</div>");
                arr.push("</td>");
                arr.push("<td width=\"80px\"  style='text-align: center;background-color: #d3eaef'>");
                arr.push("<div >操作</div>");
                arr.push("</td>");
                arr.push("</tr>");
                for (var i = 0; i < msg.msg.length; i++) {
                    if (i % 2 == 0)
                        arr.push("<tr bgcolor='#FFFFFF'>");
                    else
                        arr.push("<tr bgcolor='#EEEDED'>");
                    arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
                    arr.push(msg.msg[i].workday);
                    arr.push("</td>");
                    arr.push("<td height='20' class='STYLE6'>");
                    arr.push("<a onclick=\"Operating('" + msg.msg[i].workday + "','select','" + msg.msg[i].deptid + "')\">查看</a> <a  onclick=\"Operating('" + msg.msg[i].workday + "','delete','" + msg.msg[i].deptid + "')\">删除</a>");
                    arr.push("</td>");
                    arr.push("</tr>");

                }
                arr.push("</table>");
                document.getElementById('divlist').innerHTML = arr.join('');
            }

            function Operating(time, oper, deptid) {
                switch (oper) {
                    case "select":
                        window.location.href = "lp_Appointment.aspx?type='select'&starttime=" + time + "";
                        break;
                    case "delete":
                        if (confirm('确定要删除' + time + '的工作安排？')) {
                            ajaxdelete(time, deptid);
                        }
                        break;
                }
            }
            function ajaxdelete(time, deptid) {
                $.ajax({
                    type: "POST",
                    url: "AjaxServer.aspx",
                    dataType: 'json',
                    data: "alt=delete&time=" + time + "&deptid=" + deptid + "",
                    processData: false,
                    timeout: '10000',
                    success: function(msg) {

                        divlist(msg);

                    },
                    error: function() {
                        document.getElementById('divlist').innerHTML = "系统繁忙";
                    }

                });
            }
            function DateDiff(s1, s2) {
                //s1和s2都是2007-8-10格式 
                s1 = s1.replace(/-/g, "/");
                s2 = s2.replace(/-/g, "/");
                s1 = new Date(s1);
                s2 = new Date(s2);

                iDays = parseInt((s1 - s2) / (1000 * 60 * 60 * 24));
                return iDays;
            }
            function isTimeNotNul() {
                if (document.getElementById('txtTime').value == '') {
                    return false;
                }

//                var resultDate = DateDiff(document.getElementById('txtTime').value, document.getElementById('txtendtime').value);

//                if (resultDate > 0) {
//                    alert('请重新选择日期！结束日期不能小于开始日期');
//                    return false;
//                }
                return true;
            }
        </script>

        <div id="divlist">
            请稍候。。。
        </div>
    </div>
    </form>
</body>
</html>
